{template header}
<script type="text/javascript" src="js/popWindow.js"></script>
<script type="text/javascript">
	function docheck(){
		checksize();
		if(!checkrecipient()){
			return false;
		}
		var subject=$.trim($('#subject').val());
		if(subject==""){
			alert('{lang alertsubject}');
			return false;
		}
		var content=$.trim($('#content').val());
		if(content==""){
			alert('{lang alertcontent}');
			return false;
		}
		return true;
	}
	
	function checksubject(){
		var subject=$.trim($('#subject').val());
		if(subject==""){
			$('#subjecttip').html('&nbsp;&nbsp;{lang alertsubject}').fadeIn();
			divDance('subjecttip');
			return false;
		}else{
			$('#subjecttip').html('&nbsp;&nbsp;OK').fadeIn();
			divDance('subjecttip');
			return true;		
		}
	}

	function checkcontent(){
		var content=$.trim($('#content').val());
		if(content==""){
			$('#pmssize').html('&nbsp;&nbsp;{lang alertcontent}').fadeIn();
			divDance('pmssize');
			return false;
		}
	}
	
	function checkrecipient(){
		var sendto=$.trim($('#sendto').val());
		var result=false;
		var groupid={$groupid};
		
		if(groupid==4){
			var selectid = $.trim($('#usergroup').val());
			var draft=$('#checkbox').attr("checked");	
			if(selectid != 0 && draft){
				$('#checksendto').html('&nbsp;&nbsp;{lang systemdraft}').fadeIn();
				divDance('checksendto');
				return false;
			}
		}
			
		if(sendto==""){
			if(groupid==4 && selectid != 0){
				return true;
			}		
			$('#checksendto').html('&nbsp;&nbsp;{lang checksendto}').fadeIn();
			divDance('checksendto');
			return false;
		}else{	
			jQuery.ajax({
				url: "index.php?pms-checkrecipient",
				cache: false,
				dataType: "xml",
				type:"post",
				async:false, 
				data: { sendto: sendto },
				success: function(xml){
					var	message=xml.lastChild.firstChild.nodeValue;
					if(message!='OK'){
						$('#checksendto').html('&nbsp;&nbsp;'+message).fadeIn();
						divDance('checksendto');
					}else{
						$('#checksendto').html('OK').fadeIn();
						divDance('checksendto');
						result=true;
					}
				}
			});
			return result;
		}
	}
	
	function expand(id){
		if(id=='usermanage'){
			$("ul#usermanage").toggle(); 
		}else{
			$('ul#userpms').toggle();
		}
	}
	
	function checksize(){
		var pmssize=300-$('#content').val().length;
		if(pmssize<=0){
			$('#content').val($('#content').val().substr(0,300));
			pmssize=0;
		}
		$('#pmssize').html('{lang surplussize}&nbsp;'+pmssize+'{lang pmschar}');
		divDance('pmssize');
	}
	function changGroup(obj){
		if(obj.value != 0){
			$("#checksendto").attr('innerHTML','');
		}else{
			if(!$.trim($('#sendto').val())){
				$("#checksendto").attr('innerHTML','&nbsp;&nbsp;{lang checksendto}');
				divDance('checksendto');
			}
		}
	}
</script>
<div class="wrap hd_map">
	<a href="{WIKI_URL}">{$setting['site_name']}</a> &gt; <a href="{url pms}">{lang shortmessage}</a> &gt; {lang sendmessage}</div>
<section class="wrap clearfix">
<div class="r group1 bor-ccc gl_manage_main">
	<h2 class="col-h2">{lang sendmessage}</h2>
	<form name="sendform" action="{url pms-sendmessage}" method="post" onsubmit="return docheck();">
	<ul id="send" class="col-ul">
		<li><span class="tl">{lang sendto}</span><input id="sendto" name="sendto" type="text" class="inp_txt"  onblur="checkrecipient();" value="{$sendto}" />
		{if $usergroups}
			<select id="usergroup" name="usergroup" class="sel-row" onchange="changGroup(this)" >
				<option value="0">{lang pmschoice}</option>
				<option value="99999">{lang pmsall}</option>
				<!--{loop $usergroups $usergroup}-->
				<option value="$usergroup['groupid']">$usergroup['grouptitle']</option>
				<!--{/loop}-->
			</select>
		{/if}
		<br /><p id="checksendto" class="gray9">{lang multisend}{if $usergroups}{lang multisend1}{/if}</p></li>
		<li><span class="tl">{lang subject}</span><input name="subject" type="text" class="inp_txt" id="subject"  value="{$subject}" maxlength="35" onblur="checksubject();" /><br/><p id="subjecttip" class="gray9">{lang subjectsize}</p></li>
		<li><span class="tl">{lang content}</span><textarea cols="60" name="content" rows="6" class="inp_txt" id="content" onblur="checkcontent();" onKeyUp="checksize();">{$message}</textarea><br /><p id="pmssize" class="gray9">{lang pmssize}</p></li>
		<li><input id="checkbox" name="checkbox" type="checkbox"/><i class="checkbox"></i>{lang senddraft}</li>
		<li><input name="submit" type="submit"  value="{lang send}" class="btn_inp blue"/></li>
	</ul>
	</form>
</div>
<aside class="l group2">
<div class="sidebar bor-ccc gl_manage">
	<h2 class="col-h2 cblue"><span onclick="expand('usermanage');">{lang profile}</span></h2>	
	<ul id="usermanage">
		<li><a href="{url user-profile}" target="_self">{lang profile}</a></li>
		<li><a href="{url user-editprofile}" target="_self" >{lang editProfile}</a></li>
		<li><a href="{url user-editpass}" target="_self">{lang editPass}</a></li>
		<li><a href="{url user-editimage}" target="_self">{lang editImage}</a></li>
		<li><a href="{url doc-managesave}" target="_self">{lang manageSave}</a></li>
		<li><a href="{url user-invite}" target="_self">{lang regInvite}</a></li>
	</ul>
</div><div class="sidebar columns gl_manage">
	<h2 class="col-h2 cblue"><span onclick="expand('userpms');">{lang shortmessage}</span></h2>		
	<ul id="userpms">
		<li><a href="{url pms-box-inbox}" target="_self">{lang inbox}</a></li>
		<li><a href="{url pms-box-outbox}" target="_self" >{lang outbox}</a></li>
		<li class="on"><a href="{url pms-sendmessage}" target="_self" >{lang sendmessage}</a></li>
		<li><a href="{url pms-box-drafts}" target="_self">{lang draft}</a></li>
		<li><a href="{url pms-blacklist}" target="_self">{lang blacklist}</a></li>
	</ul>
</div>
</aside>
</section>
{template footer}